import './assets/base.css';
import './assets/main.css';
// 引入uno.css
import 'virtual:uno.css';
import { createApp } from 'vue';
import App from './App.vue';
import router from '@/router';
import { useTheme } from './composables/useTheme';
import pinia from '@/store/index.ts';
import 'element-plus/dist/index.css';
import 'ant-design-vue/dist/reset.css';
import Antd from 'ant-design-vue';
// 导入权限守卫
import { setupPermissionGuard } from '@/router/guard';
import permissionDirective from '@/directives/permission.ts';

const { applyTheme } = useTheme();

async function bootstrap() {
  // 获取保存的主题或使用默认主题
  const savedTheme = localStorage.getItem('theme') || 'light';
  applyTheme(savedTheme);
  const app = createApp(App);
  app.directive('permission', permissionDirective);

  app.use(pinia);

  // 在路由使用之前先设置权限守卫
  setupPermissionGuard(router);

  app.use(router);
  app.use(Antd);
  app.mount('#app');
}

bootstrap();
